package com.gaohe.post.controller;

import java.util.List;
import java.io.IOException;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.gaohe.common.log.annotation.Log;
import com.gaohe.common.log.enums.BusinessType;
import com.gaohe.common.security.annotation.RequiresPermissions;
import com.gaohe.post.domain.FmPostTop;
import com.gaohe.post.service.IFmPostTopService;
import com.gaohe.common.core.web.controller.BaseController;
import com.gaohe.common.core.web.domain.AjaxResult;
import com.gaohe.common.core.utils.poi.ExcelUtil;
import com.gaohe.common.core.web.page.TableDataInfo;

/**
 * 帖子置顶记录Controller
 * 
 * @author ruoyi
 * @date 2025-06-03
 */
@RestController
@RequestMapping("/top")
public class FmPostTopController extends BaseController
{
    @Autowired
    private IFmPostTopService fmPostTopService;

    /**
     * 查询帖子置顶记录列表
     */
    @RequiresPermissions("post:top:list")
    @GetMapping("/list")
    public TableDataInfo list(FmPostTop fmPostTop)
    {
        startPage();
        List<FmPostTop> list = fmPostTopService.selectFmPostTopList(fmPostTop);
        return getDataTable(list);
    }

    /**
     * 导出帖子置顶记录列表
     */
    @RequiresPermissions("post:top:export")
    @Log(title = "帖子置顶记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FmPostTop fmPostTop)
    {
        List<FmPostTop> list = fmPostTopService.selectFmPostTopList(fmPostTop);
        ExcelUtil<FmPostTop> util = new ExcelUtil<FmPostTop>(FmPostTop.class);
        util.exportExcel(response, list, "帖子置顶记录数据");
    }

    /**
     * 获取帖子置顶记录详细信息
     */
    @RequiresPermissions("post:top:query")
    @GetMapping(value = "/{postTopId}")
    public AjaxResult getInfo(@PathVariable("postTopId") Long postTopId)
    {
        return success(fmPostTopService.selectFmPostTopByPostTopId(postTopId));
    }

    /**
     * 新增帖子置顶记录
     */
    @RequiresPermissions("post:top:add")
    @Log(title = "帖子置顶记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FmPostTop fmPostTop)
    {
        return toAjax(fmPostTopService.insertFmPostTop(fmPostTop));
    }

    /**
     * 修改帖子置顶记录
     */
    @RequiresPermissions("post:top:edit")
    @Log(title = "帖子置顶记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FmPostTop fmPostTop)
    {
        return toAjax(fmPostTopService.updateFmPostTop(fmPostTop));
    }

    /**
     * 删除帖子置顶记录
     */
    @RequiresPermissions("post:top:remove")
    @Log(title = "帖子置顶记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{postTopIds}")
    public AjaxResult remove(@PathVariable Long[] postTopIds)
    {
        return toAjax(fmPostTopService.deleteFmPostTopByPostTopIds(postTopIds));
    }
}
